package _05Array;

import java.util.Arrays;
import java.util.Comparator;

public class zidingyisort {
    public static void main(String[] args) {
        book[] books = new book[3];
        books[0]=new book("父与子", 14);
        books[1]= new book("三国演义", 66);
        books[2] = new book("十万个为什莫", 43);
        Arrays.sort(books,new Comparator<book>() {
            @Override
            public int compare(book o1, book o2) {
                return o1.getName().length()-o2.getName().length();
            }
        });
        System.out.println(books[0].getName()+books[0].getPrice());
        System.out.println(books[1].getName()+books[1].getPrice());
        System.out.println(books[2].getName()+books[2].getPrice());
    }
}
class book{
    private String name;
    private int price;
    public book(String name,int price){
        this.name=name;
        this.price=price;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setPrice(int price) {
        this.price = price;
    }
    public String getName() {
        return name;
    }
    public int getPrice() {
        return price;
    }

}
